$.fn.formEdit = function(data) {
	return this.each(function() {
		var input, name;
		if(data == null) {
			this.reset();
			return;
		}
		for(var i = 0; i < this.length; i++) {
			input = this.elements[i];
			//checkbox的name可能是name[]数组形式
			name = (input.type == "checkbox") ? input.name.replace(/(.+)\[\]$/, "$1") : input.name;
			if(data[name] == undefined) continue;
			switch(input.type) {
				case "checkbox":
					if(data[name] == "") {
						input.checked = false;
					} else {
						//数组查找元素
						if(data[name].indexOf(input.value) > -1) {
							input.checked = true;
						} else {
							input.checked = false;
						}
					}
					break;
				case "radio":
					if(data[name] == "") {
						input.checked = false;
					} else if(input.value == data[name]) {
						input.checked = true;
					}
					break;
				case "button":
					break;
				default:
					input.value = data[name];
			}
		}
	});
};


function cenheighta() {
	var navHeight = $(".center-tit").outerHeight();
	var cenHeight = $(".center-nav").outerHeight();
	var scrHeight = $(".screen-bnt-cen").outerHeight();
	var pagHeight = $(".paging").outerHeight();
	$(".center-tab").height($("body").height() - navHeight - cenHeight - scrHeight - pagHeight - 60)
	
	
}

function curretLen(){
	
	if($(".list-table tbody .tr-current").length>0){
		$(".center-nav ul li a.hb-bnt").addClass("hov").removeClass("hov-n");
	}else{
		$(".center-nav ul li a.hb-bnt").removeClass("hov").addClass("hov-n");
	}
	
	
}
function CheckTrue(check){
	if(check==true){
		$(".center-nav ul li a.hb-bnt").addClass("hov").removeClass("hov-n");
	}else{
		$(".center-nav ul li a.hb-bnt").removeClass("hov").addClass("hov-n");
	}
}


function CheckQ($whole,$single){
	$($whole).click(function(){
		if($(this).is(':checked')){
			$($single).prop("checked",true);
		}else{
			$($single).prop("checked",false);
		}
		for (var i=0;i<$($single).length;i++) {
			if($($single).eq(i).is(':checked')){
				$($single).eq(i).parents(".list-tr").addClass("tr-current");
			}else{
				$($single).eq(i).parents(".list-tr").removeClass("tr-current");
			}
		}
		curretLen();
	})
}

function CheckD($obj){
	$($obj).on("click","input.single-whole",function(){
		if($(this).is(':checked')){
			$(this).prop("checked",true);
			$(this).parents(".list-tr").addClass("tr-current");
		}else{
			$(this).prop("checked",false);
			$(this).parents(".list-tr").removeClass("tr-current");
		}
		curretLen();
		
	})
}

//会员等级
function levelFun(){
	$.ajax({
		type:"get",
		url:levelApi,
		success:function(data){
			var code=data.code;
			if(code==1){
				var levelHtml='<option value="">请选择会员等级</option>'
				$.each(data.data,function(index,value){
					levelHtml+='<option value="'+value.id+'">'+value.level_name+'</option>';
				});
				$(".level-input").html(levelHtml);
				$("body").append('<select id="levelHtml">'+levelHtml+'</select>')
			}
		}
	});
}


//会员状态
function statusFun(){
	$.ajax({
		type:"get",
		url:statusApi,
		success:function(data){
			var statusHtml='<option value="">请选择会员状态</option>'
			$.each(data,function(index,value){
				statusHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".status-input").html(statusHtml);
			$("body").append('<select id="statusHtml">'+statusHtml+'</select>');
		}
	});
}
//代理中心
function agentFun(){
	$.ajax({
		type:"get",
		url:agentApi,
		success:function(data){
			var agentHtml='<option value="">请选择是否代理中心</option>'
			$.each(data,function(index,value){
				agentHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".member-is-agent").html(agentHtml);
			$("body").append('<select id="agentHtml">'+agentHtml+'</select>');
		}
	});
}

//订单状态
function statusOrderFun(){
	$.ajax({
		type:"get",
		url:statusOrderApi,
		success:function(data){
			var code = data.code;
			var msg = data.msg;
			var data = data.data;
			if(code==1){
				var statusOrderHtml='<option value="">请选择订单状态</option>'
				$.each(data,function(index,value){
					statusOrderHtml+='<option value="'+index+'">'+value+'</option>';
				});
				$(".status-order").html(statusOrderHtml);
				$("body").append('<select id="statusOrderHtml">'+statusOrderHtml+'</select>');
			}else{
				alert("订单状态列表获取失败");
			}
			
			
		}
	});
}


//会员安置大区
function areaFun(){
	$.ajax({
		type:"get",
		url:areaApi,
		success:function(data){
			var areaHtml='<option value="">请选择所在大区</option>'
			$.each(data,function(index,value){
				areaHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".member-area").html(areaHtml);
			$("body").append('<select id="areaHtml">'+areaHtml+'</select>');
		}
	});
}


//会员类型
function typeFun(){
	$.ajax({
		type:"get",
		url:typeApi,
		success:function(data){
			var typeHtml='<option value="">请选择会员类型</option>'
			$.each(data,function(index,value){
				typeHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".member-type").html(typeHtml);
			$("body").append('<select id="typeHtml">'+typeHtml+'</select>');
		}
	});
}

//货币
function cionFun(){
	$.ajax({
		type:"get",
		url:cionApi,
		success:function(data){
			var cionHtml='<option value="">请选择货币类型</option>'
			$.each(data,function(index,value){
				cionHtml+='<option value="'+value.id+'">'+value.coin_name+'</option>';
			});
			$(".cion-type").html(cionHtml);
			$("body").append('<select id="cionHtml">'+cionHtml+'</select>');
		}
	});
}

//充值
function chargefun(){
	$.ajax({
		type:"get",
		url:chargeApi,
		success:function(data){
			var chargeHtml='<option value="">请选择状态</option>'
			$.each(data,function(index,value){
				chargeHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".charge-type").html(chargeHtml);
			$("body").append('<select id="chargeHtml">'+chargeHtml+'</select>');
		}
	});
}
//转账
function transferfun(){
	$.ajax({
		type:"get",
		url:transferApi,
		success:function(data){
			var transferHtml='<option value="">请选择状态</option>'
			$.each(data,function(index,value){
				transferHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".transfer-type").html(transferHtml);
			$("body").append('<select id="transferHtml">'+transferHtml+'</select>');
		}
	});
}
//转换
function convertfun(){
	$.ajax({
		type:"get",
		url:convertApi,
		success:function(data){
			var convertHtml='<option value="">请选择状态</option>'
			$.each(data,function(index,value){
				convertHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".convert-type").html(convertHtml);
			$("body").append('<select id="convertHtml">'+convertHtml+'</select>');
		}
	});
}
//提现

function withdrawfun(){
	$.ajax({
		type:"get",
		url:withdrawApi,
		success:function(data){
			var withdrawHtml='<option value="">请选择状态</option>'
			$.each(data,function(index,value){
				withdrawHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".withdraw-type").html(withdrawHtml);
			$("body").append('<select id="withdrawHtml">'+withdrawHtml+'</select>');
		}
	});
}

//增减
function flagFun(){
	$.ajax({
		type:"get",
		url:flagApi,
		success:function(data){
			var flagHtml='<option value="">请选择增减状态</option>'
			$.each(data,function(index,value){
				flagHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".flag-type").html(flagHtml);
			$("body").append('<select id="cflagHtml">'+flagHtml+'</select>');
		}
	});
}

function bonusFun(){
	$.ajax({
		type:"get",
		url:bonusApi,
		success:function(data){
			var bonusHtml='<option value="">请选择奖金类型</option>'
			$.each(data,function(index,value){
				bonusHtml+='<option value="'+value.bonus_name+'">'+value.bonus_tag+'</option>';
			});
			$(".bonus-type").html(bonusHtml);
			$("body").append('<select id="bonusHtml">'+bonusHtml+'</select>');
		}
	});
}

//记录类型
function recordFun(){
	$.ajax({
		type:"get",
		url:recordApi,
		success:function(data){
			var recordHtml='<option value="">请选择记录类型</option>'
			$.each(data,function(index,value){
				recordHtml+='<option value="'+index+'">'+value+'</option>';
			});
			$(".record-type").html(recordHtml);
			$("body").append('<select id="recordHtml">'+recordHtml+'</select>');
		}
	});
}


//地区联动菜单
function provFun(){
	$.ajax({
		type:"get",
		url:cryApi,
		success:function(data){
			listHtml='<option value="">请选择省份</option>'
			$.each(data,function(index,value){
				listHtml+='<option value="'+value.id+'">'+value.name+'</option>';
			});
			$("#prov").html(listHtml);
		}
	});
}
function cityFun($this){
	var id=$this.val();
	$.ajax({
		type:"get",
		url:cryApi,
		data:{
			id:id
		},
		success:function(data){
			listHtml='<option value="">请选择城市</option>'
			$.each(data,function(index,value){
				listHtml+='<option value="'+value.id+'">'+value.name+'</option>';
			});
			$("#city").html(listHtml);
			$("#town").html('<option value="">请选择县区</option>');
		}
	});
	
}
function townFun($this){
	var id=$this.val();
	$.ajax({
		type:"get",
		url:cryApi,
		data:{
			id:id
		},
		success:function(data){
			listHtml='<option value="">请选择县区</option>'
			$.each(data,function(index,value){
				listHtml+='<option value="'+value.id+'">'+value.name+'</option>';
			});
			$("#town").html(listHtml);
		}
	});
	
}

function townFun($this){
	var id=$this.val();
	$.ajax({
		type:"get",
		url:cryApi,
		data:{
			id:id
		},
		success:function(data){
			listHtml='<option value="">请选择</option>'
			$.each(data,function(index,value){
				listHtml+='<option value="'+value.id+'">'+value.name+'</option>';
			});
			$("#town").html(listHtml);
		}
	});
	
}

//
//function eidtPro(){
//	
//  		
//}

$(function() {
	//表格列表高度
     cenheighta();

	$(window).resize(function() {
		location.reload()
	});
	
	
	//全选单选
	CheckQ("#check-whole",".single-whole");
	CheckD(".list-table tbody");
})